#!/usr/bin/python3.8
# -*- coding: utf-8 -*-
# @Time    : 2021/3/5 09:04
# @Author  : zhaohexin
# @Email   : 1483643520@xxx.com
# @File    : security.py
# @Software: PyCharm
# @FileDescription：密码加密/验证等


from passlib.context import CryptContext

pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


def get_password(password: str) -> str:
    """
    获取加密后密码
    :param password:
    :return:
    """
    return pwd_context.encrypt(password)


def verify_password(plain_password: str, hashed_password: str) -> bool:
    """
    对比密码
    :param plain_password: 前端传入密码
    :param hashed_password: 数据库加密的密码
    :return:
    """
    return pwd_context.verify(plain_password, hashed_password)